package com.heima.homeworkone.controller;

import com.heima.homeworkone.bean.Dept;
import com.heima.homeworkone.bean.Result;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/depts")
public class demoController {

    //新增部门
    @PostMapping
    public Result save(@RequestBody Dept dept){
        System.out.println("新增部门"+dept);

        return Result.success("新增成功");
    }

    //根据ID删除部门
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id){
        System.out.println("删除部门"+id);
        return Result.success("删除成功");
    }

    //根据ID修改部门
    @PutMapping
    public Result update(@RequestBody Dept dept){
        System.out.println("修改部门"+dept);
        return Result.success("修改成功");
    }

    //根据ID查询部门
    @GetMapping("/{id}")
    public Result getById(@PathVariable("id") Integer id){
        System.out.println("查询部门"+id);
        Dept dept = new Dept();
        dept.setId(id);
        dept.setName("IT部");
        System.out.println(dept);
        return Result.success(dept);
    }

    //查询所有部门
    @GetMapping
    public Result getAll(){
        System.out.println("查询所有部门");
        List<Dept> list=new ArrayList<>();
        Dept dept1=new Dept();
        dept1.setId(1);
        dept1.setName("IT部");
        dept1.setUser("张三");
        list.add(dept1);
        Dept dept2=new Dept();
        dept2.setId(2);
        dept2.setName("财务部");
        dept2.setUser("李四");
        list.add(dept2);
        System.out.println(list);
        return Result.success(list);
    }





}
